package com.gareve.twoSides.views;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.FPSLogger;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer.ShapeType;
import com.gareve.twoSides.GameConstants;
import com.gareve.twoSides.models.GameWorld;
import com.gareve.twoSides.models.Obstacle;

public class GameRenderer {
	private GameWorld gameWorld;
	public OrthographicCamera camera;
	private ShapeRenderer shapeRenderer = new ShapeRenderer();
	private FPSLogger fpsLogger = new FPSLogger();
	
	public void setGameWorld(GameWorld gameWorld) {
		this.gameWorld = gameWorld;
		
		camera = new OrthographicCamera(GameConstants.SCREEN_WIDTH,GameConstants.SCREEN_HEIGHT);
		camera.position.x = GameConstants.SCREEN_WIDTH / 2f;
		camera.position.y = GameConstants.SCREEN_HEIGHT / 2f;
		camera.update();
	}

	float angle = 0.1f;

	private void initCamera() {
		//camera.rotate(angle);
		//camera.update();

		shapeRenderer.setProjectionMatrix(camera.combined);

		Gdx.gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);
		Gdx.gl.glClearColor(0.1f, 0.1f, 0.1f, 1);
		Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);

		fpsLogger.log();		
	}

	public void render() {
		initCamera();
		
		gameWorld.playerObjectA.render(shapeRenderer);
		gameWorld.playerObjectB.render(shapeRenderer);
		
		gameWorld.obstacleGenerator.render(shapeRenderer);
		
		for(Obstacle obstacle : gameWorld.obstacles)
			obstacle.render(shapeRenderer);		
	}
}
